//
//  FeedbackVC.m
//  UHealth
//
//  Created by hanyou on 15/3/19.
//  Copyright (c) 2015年 gjtx. All rights reserved.
//

#import "FeedbackVC.h"
#import "NavView.h"

@interface FeedbackVC ()

@property (nonatomic,strong)UITextView *field;

@end

@implementation FeedbackVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.view.backgroundColor = kBacColor;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    NavView *nav = [[NavView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kNavHeight) andTitleStr:kLocal(@"feedback") andVC:self];
    [self.view addSubview:nav];
    
    _field = [[UITextView alloc]initWithFrame:CGRectMake(10, kNavHeight+10, WIDTH - 20, 84)];
    _field.text = kLocal(@"feedbackPla");
    _field.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:_field];
    
    UIButton *buyBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    buyBtn.frame = CGRectMake(10, kNavHeight+15 +84, WIDTH-20, 40);
    [buyBtn.layer setMasksToBounds:YES];
    [buyBtn.layer setCornerRadius:1.0];//设置矩形是个圆角半径
    buyBtn.backgroundColor = kBlueColor;
    [buyBtn setTitle:kLocal(@"commit") forState:UIControlStateNormal];
    [buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buyBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buyBtn];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, kNavHeight+15 +84+40+10, WIDTH-20, 42)];
    label.numberOfLines = 2;
    label.textColor = [UIColor grayColor];
    label.text = kLocal(@"feedbackHit");
    label.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:label];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)btnClick:(UIButton *)btn{
    
    if (_field.text.length<=0) {
        [[iToast makeText:kLocal(@"please_fill_content")] show];
    }
    if (!kNetID) {
        [[iToast makeText:kLocal(@"notLogin")]show];
        return;
    }
    if (!kNetIsOK) {
        [[iToast makeText:kLocal(@"netNoOk")]show];
        return;
    }
    
    
    AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer.timeoutInterval = 10;
    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject: @"text/html"];
    NSString *postStr = [NSString stringWithFormat:@"%@/action/json/sysapp.jsp?",kBaseUrl];
    NSDictionary * parameters = @{@"action": @"SetAppFeedback",
                                  @"userid":[NSString stringWithFormat:@"%d",(int)kNetID],
                                  @"apptype":@"iOS",
                                  @"content":_field.text};
    
    [manager POST:postStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        kDebug(@"Success: %@", operation.responseString);
        BOOL type = [[responseObject objectForKey:@"type"] boolValue];
        if(type){//成功
        }else{
            
        }
        [[iToast makeText:[responseObject objectForKey:@"msg"]] show];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        kDebug(@"Error: %@", error);
        [[iToast makeText:kLocal(@"netError")] show];
    }];


    

    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
